package com.autumn.platform.web.exceptionresolver;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.support.ModelAndViewContainer;

@RestController
@ControllerAdvice
public class ExceptionResolverControllerAdvice {

    @ExceptionHandler
    public Object resolveException(Throwable t, ModelAndViewContainer mavContainer, HttpServletRequest request, HttpServletResponse response) throws NumberFormatException, IOException {
        // chrome浏览器中可以在发送非200代码的同时，返回json数据，但是IE表现不一样，为了统一处理，这里直接返回
        //        IResponse status = ExceptionStatusResolver.resolveStatus(t);
        //        if (null != status && !status.isSuccess()) {
        //            response.setStatus(Integer.parseInt(status.getCode()));
        //        }
        response.setCharacterEncoding("UTF-8");
        return t;
    }
}
